﻿using System;
using System.Collections.Generic;
using STeaL.Functional;

namespace STeaL.Algorithm {

  public static partial class IListExtensions {
#region all_of
    public static bool all_of<T>(this IList<T> list, int first, int last, Func<T,bool> pred) {
      for ( ; first != last; ++first ) {
        if ( !pred(list[first]) ) return false;
      }
      return true;
    }

    public static bool all_of<T>(this IList<T> list, Func<T,bool> pred) {
      return all_of(list, 0, list.Count, pred);
    }

#endregion
#region any_of
    public static bool any_of<T>(this IList<T> list, int first, int last, Func<T,bool> pred) {
      for ( ; first != last; ++first ) {
        if ( pred(list[first]) ) return true;
      }
      return false;
    }

    public static bool any_of<T>(this IList<T> list, Func<T,bool> pred) {
      return any_of(list, 0, list.Count, pred);
    }

#endregion
#region none_of
    public static bool none_of<T>(this IList<T> list, int first, int last, Func<T,bool> pred) {
      for ( ; first != last; ++first ) {
        if ( pred(list[first]) ) return false;
      }
      return true;
    }

    public static bool none_of<T>(this IList<T> list, Func<T,bool> pred) {
      return none_of(list, 0, list.Count, pred);
    }

#endregion
  }
}
